package com.blb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blb.entity.Notes;
import com.blb.service.INotesService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.websocket.Session;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gk
 * @since 2019-12-25
 */

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/notes")
public class NotesController {

    @Resource
    private INotesService notesService;


    /**
     * 获取所有回收站的笔记
     * @return
     */
    @GetMapping("recycle")
    public List<Notes> notes(){
        List<Notes> list = notesService.list(new QueryWrapper<Notes>().eq("recycle", "1"));
        //判断md文件/普通文件
        for (Notes note:list) {
            if (note.getType().equals("0")){
                note.setNotesName(note.getNotesName()+".md");
            }
        }
        return list;
    }


    /**
     *后台接受笔记id，修改回收状态为0
     */
    @RequestMapping("update")
    public void updateNotes( String id){
        Notes notes = notesService.getById(id);
        notes.setRecycle("0");
        notesService.updateById(notes);
    }

    /**
     * 回收站删除
     */
    @RequestMapping("delete")
    public void deleteNotes(String id){
        notesService.removeById(id);
    }



}

